package com.xapp.baseContent;

import android.app.Application;
import android.content.Context;



import com.xapp.utils.SystemUtils;


import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class MyApplication extends Application {

    private String TAG = "MyApplication";
    public static String deviceName="";

    @Override
    public void onCreate() {
        super.onCreate();

    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }

    @Override
    protected void attachBaseContext(Context base) {
        if ("OPPO".equals(SystemUtils.getDeviceBrand())) {
            fixOppoAssetManagerBug();
        }
        super.attachBaseContext(base);
    }

    //oppo手机修改rom，会导致assetmanager超时
    // https://blog.csdn.net/zlmrche/article/details/81365204
    //http://www.courtier.cc/2017/04/28/%E5%85%B3%E4%BA%8Etimeoutexception%E8%BF%99%E4%BB%B6%E5%B0%8F%E4%BA%8B/
    private void fixOppoAssetManagerBug() {
        try {
            Class clazz = Class.forName("java.lang.Daemons$FinalizerWatchdogDaemon");
            Method stopMethod = clazz.getSuperclass().getDeclaredMethod("stop");
            stopMethod.setAccessible(true);

            Field field = clazz.getDeclaredField("INSTANCE");
            field.setAccessible(true);

            stopMethod.invoke(field.get(null));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
